home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-06 | 6.1 KB | 260 lines | [TEXT/MPS ] |
- UNIT LToLDragUnit;
-
- INTERFACE
-
- USES
- MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf;
-
- PROCEDURE InitLtoLDrag;
- {Initialize the unit's global variables}
-
- PROCEDURE SetDragEnvironment (DestDialog :
- DialogPtr);
- {Call this procedure when you switch dialogs}
-
- FUNCTION LtoLClickProc : BOOLEAN;
- {The 'item dragging' Clickproc}
-
- CONST
- kDragToOwnList = $01;
- kDragToOtherList = $02;
- kDragOutside = $04;
-
- {$i DragUnitUserDefs.i}
-
- IMPLEMENTATION
-
- VAR
- gSourceList : ListHandle;
- gDestLists : ARRAY [1..10] OF ListHandle;
- gNumDestLists : Integer;
- gTheDialog : DialogPtr;
- gDragStyle : Integer;
- AnchorDefined : BOOLEAN;
- AnchorPoint,
- OldPoint,
- NextPoint : Point;
-
- CONST
- kInvalidDrag = $8000;
- kMaxDestLists = 10;
-
- {The following routines should be defined by}
- {the programmer in DragUnitUserProcs.i}
- PROCEDURE DragToDestAction (SourceList : ListHandle; SourceCell : Point; DestList :
- ListHandle; DestCell : Point); FORWARD;
- PROCEDURE DragToSourceAction (SourceList :
- ListHandle; SourceCell : Point; DestList :
- ListHandle; DestCell : Point); FORWARD;
- PROCEDURE BadDragAction (SourceList :
- ListHandle; SourceCell : Point); FORWARD;
- PROCEDURE DragOutsideAction (SourceList :
- ListHandle; SourceCell : Point); FORWARD;
- PROCEDURE SetSourceDestLists (ClickPt : Point);
- FORWARD;
-
- {------------------------------------------------}
-
- PROCEDURE InitLtoLDrag;
- VAR
- i : Integer;
- BEGIN
- SetPt(AnchorPoint, 0, 0);
- AnchorDefined := FALSE;
- OldPoint := AnchorPoint;
- NextPoint := AnchorPoint;
- gSourceList := NIL;
- FOR i := 1 TO kMaxDestLists DO
- gDestLists[i] := NIL;
- gNumdestLists := 0;
- END;
-
- {------------------------------------------------}
-
- PROCEDURE SetDragEnvironment (DestDialog :
- DialogPtr);
- BEGIN
- gTheDialog := DestDialog;
- END;
-
- {------------------------------------------------}
-
- FUNCTION FindCell(VAR Selected_Cell :
- Point; TheList : ListHandle) : BOOLEAN;
- {Return the currently selected cell in TheList}
- BEGIN
- SetPt(Selected_Cell, 0, 0);
- FindCell:= LGetSelect(TRUE,
- Selected_Cell, TheList);
- END;
-
- {------------------------------------------------}
-
- FUNCTION CanDragToSelf : BOOLEAN;
- BEGIN
- CanDragToSelf := BAND(kDragToOwnList,
- gDragStyle) > 0;
- END;
-
- {------------------------------------------------}
-
- FUNCTION CanDragToOther : BOOLEAN;
- BEGIN
- CanDragToOther := BAND(kDragToOtherList,
- gDragStyle) > 0
- END;
-
- {------------------------------------------------}
-
- FUNCTION CanDragOutside : BOOLEAN;
- BEGIN
- CanDragOutside := BAND(kDragOutSide, gDragStyle)
- > 0;
- END;
-
- {------------------------------------------------}
-
- PROCEDURE DragProc;
- VAR
- MPos : Point;
- WhichCell : Point;
- TempRect : Rect;
- i : Integer;
-
- PROCEDURE CheckList(TheList:ListHandle);
- BEGIN
- IF TheList = NIL THEN
- EXIT(CheckList);
- TempRect := TheList^^.rView;
- IF PtInRect(MPos, TempRect) THEN
- BEGIN
- MPos.v := ((MPos.v - TempRect.Top) DIV
- TheList^^.CellSize.v) +
- TheList^^.Visible.Top;
- MPos.h := 0;
- IF FindCell(WhichCell, TheList) THEN
- BEGIN
- IF NOT(EqualPt(WhichCell, MPos)) THEN
- BEGIN
- LSetSelect (FALSE, WhichCell, TheList);
- LSetSelect (TRUE, MPos, TheList);
- END; {equalpt}
- END {FindCell}
- ELSE
- LSetSelect (TRUE, MPos, TheList);
- END; {PtInRect}
- END;
-
- BEGIN
- GetMouse(MPos);
- IF CanDragToSelf THEN
- CheckList(gSourceList);
-
- IF CanDragToOther THEN
- FOR i := 1 TO gNumDestLists DO
- CheckList(gDestLists[i]);
- END;
-
- FUNCTION LtoLClickProc : BOOLEAN;
- VAR
- R : RgnHandle;
- OldState : PenState;
- TT, L : LongInt;
- B : BOOLEAN;
- DestCell, SourceCell,
- SelectedCell : Point;
- CellRect : Rect;
- LimitRect, SlopRect : Rect;
- i : Integer;
- TempRect : Rect;
- BEGIN
- LtoLClickProc := TRUE;
- IF NOT(AnchorDefined) THEN
- BEGIN
- AnchorDefined := TRUE; {store the point where}
- GetMouse(AnchorPoint); {we initially clicked }
- {Call this to set the lists we can drag to}
- SetSourceDestLists (AnchorPoint);
- EXIT(LtoLClickProc); {exit here so that}
- END {the cell will be hilighted}
- ELSE
- AnchorDefined := FALSE;
-
- IF FindCell(SourceCell, gSourceList) THEN
- BEGIN
- LRect(CellRect, SourceCell, gSourceList);
- IF CanDragToSelf & NOT(CanDragToOther) THEN
- BEGIN
- SetRect(LimitRect, gSourceList^^.rView.Left +
- (AnchorPoint.h - CellRect.Left),
- gSourceList^^.rView.Top +
- (AnchorPoint.v - CellRect.Top),
- gSourceList^^.rView.Right -
- (CellRect.Right - AnchorPoint.h),
- gSourceList^^.rView.Bottom - (CellRect.Bottom - AnchorPoint.v));
- SlopRect := gSourceList^^.rView;
- END
- ELSE
- BEGIN
- SetRect(LimitRect, gTheDialog^.PortRect.Left
- + (AnchorPoint.h - CellRect.Left),
- gTheDialog^.PortRect.Top +
- (AnchorPoint.v - CellRect.Top),
- gTheDialog^.PortRect.Right -
- (CellRect.Right - AnchorPoint.h),
- gTheDialog^.PortRect.Bottom -
- (CellRect.Bottom - AnchorPoint.v));
- SlopRect := gTheDialog^.PortRect;
- END;
- {now that we have selected a cell, use}
- {DragGrayRgn to drag it around}
- InsetRect (SlopRect, -1, -1);
- R := NewRgn;
- RectRgn(R, CellRect);
- L := DragGrayRgn(R, AnchorPoint, LimitRect,
- SlopRect, noConstraint, @DragProc);
- IF HiWord(L) = kInvalidDrag THEN
- BadDragAction (gSourceList, SourceCell)
- ELSE
- BEGIN
- DestCell.v := AnchorPoint.v + HiWord(L);
- DestCell.h := AnchorPoint.h + LoWord(L);
- IF PtInRect(DestCell, gSourceList^^.rView) &
- CanDragToSelf THEN
- BEGIN
- IF FindCell(DestCell, gSourceList) THEN
- DragToSourceAction (gSourceList,
- SourceCell, gSourceList, DestCell);
- END
- ELSE
- BEGIN
- IF CanDragToOther THEN
- BEGIN
- FOR i := 1 TO gNumDestLists DO
- BEGIN
- IF (gDestLists[i] <> NIL) &
- (PtInRect(DestCell,
- gDestLists[i]^^.rView)) &
- FindCell(DestCell, gDestLists[i])
- THEN
- BEGIN
- DragToDestAction (gSourceList,
- SourceCell, gDestLists[i],
- DestCell);
- EXIT(LtoLClickProc);
- END; {if FindCell}
- END; {for}
- END; {if CanDragToOther}
-
- IF CanDragOutSide THEN
- DragOutsideAction (gSourceList,
- SourceCell);
- END; {else}
- END; {if not kinvaliddrag}
- END; {FindCell}
- END; {LtoLClickProc}
-
- {$i DragUnitUserProcs.i}
- END.
-
-